package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.common.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐管理")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @RequestMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("分页查询：{}",setmealPageQueryDTO);
        return setmealService.page(setmealPageQueryDTO);
    }
    @PostMapping
    @ApiOperation("新增套餐")
    public Result<String> add(@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐：{}",setmealDTO);
        return setmealService.add(setmealDTO) ? Result.success("新增成功") : Result.error("新增失败");
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> findById(@PathVariable Long id){
        log.info("根据id查询套餐：{}",id);
        return Result.success(setmealService.findById(id));
    }
    @PutMapping
    @ApiOperation("修改套餐")
    public Result<String> update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐：{}",setmealDTO);
        return setmealService.update(setmealDTO) ? Result.success("修改成功") : Result.error("修改失败");
    }
    @PostMapping("/status/{status}")
    @ApiOperation("起售、停售套餐")
    public Result<String> startOrStop(@PathVariable Integer status,Long id){
        log.info("起售、停售套餐：{}",id);
        return setmealService.startOrStop(status,id) ? Result.success("操作成功") : Result.error("操作失败");
    }
    @DeleteMapping
    @ApiOperation("批量删除套餐")
    public Result<String> delete(@RequestParam List<Long> ids){
        log.info("批量删除套餐：{}",ids);
        return setmealService.delete(ids) ? Result.success("删除成功") : Result.error("删除失败");
    }
}
